/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.core.service.processor.store;

import com.google.common.collect.Lists;
import info.peigen.hotpot.business.account.core.domain.account.AccountTransfer;
import info.peigen.hotpot.business.account.core.service.processor.base.AbstractAccountServiceProcessor;
import info.peigen.hotpot.business.account.facade.enums.AccountTransCode;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(StoreAccountTransferProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/5/26
 */
@SuppressWarnings("rawtypes")
@Component
public class StoreAccountTransferProcessor extends AbstractAccountServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 90;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        AccountTransfer transfer = (AccountTransfer) serviceContext.getDomain();
        accountRepository.batchStoreAccount(Lists.newArrayList(transfer.getPayeeAccount(), transfer.getPayerAccount(), transfer.getProvisionsAccount(), transfer.getFeePayerAccount(), transfer.getFeePayeeAccount()));
        accountRepository.batchStoreAccountLog(transfer.getAccountLogs());
        if (transfer.getTransCode() == AccountTransCode.Transfer) {
            accountRepository.store(transfer.getAccountTransLog());
        }
    }
}
